# 作者；吴同学
# 2025年 01月 03日 14时 55分 06秒
# 1207570802@qq.com

# 1、练习深copy与浅copy
import copy
import re


def shallow_copy():
    list1 = [[1, 2], [3, 4], [5, 6]]
    list2 = list1.copy()
    list1[0][0] = 4
    print(list1)
    print(list2)


def deep_copy():
    list1 = [[1, 2], [3, 4], [5, 6]]
    list2 = copy.deepcopy(list1)
    list1[0][0] = 4
    print(list1)
    print(list2)

# 2、练习上课匹配单个字符，多个字符，匹配分组的正则表达式案例


def re_test():
    text = 'python'
    match = re.search(r'a', text)
    if match:
        print("匹配成功!", match.group())
    else:
        print("匹配失败!")


def re_test2():
    text = 'python'
    match = re.search(r'.', text)
    if match:
        print("匹配成功!", match.group())
    else:
        print("匹配失败!")


def re_test3():
    text = 'python'
    match = re.search(r'\d', text)
    if match:
        print("匹配成功!", match.group())
    else:
        print("匹配失败!")


def re_phone_number():
    phone = r'^1[3-9]\d{9}$'
    while True:
        numbers = input('请输入电话号码: ')
        if re.match(phone, numbers):
            print(f'您的电话号码是:{numbers}')
            break
        else:
            print('输入格式有误!')

# 3、练习上课的search，findall,sub等案例


def re_phone_number_find():
    phone_number = '14345678901, 1234, 1234556, 15223456789'
    phone_pattern = r'1[3-9]\d{9}'
    result = re.search(phone_pattern, phone_number)

    if result:
        print(f'find one number is {result.group()}')
    else:
        print('can\'t find number')
    all_result = re.findall(phone_pattern, phone_number)
    print(f'all numbers are {all_result}')

    sub_result = re.sub(phone_pattern, '666', phone_number)
    print(sub_result)


if __name__ == '__main__':
    # shallow_copy()
    # deep_copy()
    # re_test()
    # re_test2()
    # re_test3()
    # re_phone_number()
    re_phone_number_find()
